// pages/history/history.js
const app = getApp();
import api from '../../utils/api.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    questionTab: [
      { text: '题库', icon: '/images/question.png', selectedIcon: '/images/question_active.png' },
      { text: '历史', icon: '/images/history.png', selectedIcon: '/images/history_active.png' },
      { text: '我的', icon: '/images/my.png', selectedIcon: '/images/my_active.png' }
    ],
    currentTabbarIndex: 1,

    tabControl: ['题库复习','真题考试'],
    currentTabControlIndex: 0
  },

  change(e) {
    this.setData({
      currentTabbarIndex: e.currentTarget.dataset.index
    })
    if (this.data.currentTabbarIndex == 0) {
      wx.redirectTo({
        url: '/pages/question/question',
      })
    } else if (this.data.currentTabbarIndex == 1) {
      wx.redirectTo({
        url: '/pages/history/history',
      })
    } else {
      wx.redirectTo({
        url: '/pages/my/my',
      })
    }

  },

  changeIndex(e){
    this.setData({
      currentTabControlIndex: e.currentTarget.dataset.index
    })
    this.getChapterList()
  },

  getChapterList(){
    api.POST('applet/customerPaper/finds', { type: this.data.currentTabControlIndex + 1},
    res=>{
      console.log(res)
      this.setData({
        chapterList: res.data.data
      })
    })
  },

  goToTestSituation(e) {
    let obj = {
      type: e.currentTarget.dataset.item.type, //1是练习 2是真题
      paper_id: e.currentTarget.dataset.item.paper_id,
      totalNum: e.currentTarget.dataset.item.totalNum, //总题数
      subjectNum: e.currentTarget.dataset.item.subject_num, //已做题
      paper_category_id: e.currentTarget.dataset.item.paper_category_id, //三级id
      timing: e.currentTarget.dataset.item.timing,
      lastTime: e.currentTarget.dataset.item.last_timing, //已用时间
      name: e.currentTarget.dataset.item.name
    }
    app.globalData.test = obj
    wx.navigateTo({
      url: '/pages/testSituation/testSituation'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      windowHeight:app.globalData.windowHeight
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getChapterList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})